package com.zhj.util.state.switchs;

import com.zhj.util.state.StateHandleException;
import com.zhj.util.state.enems.PreRegEventEnum;
import com.zhj.util.state.enems.PreRegStateEnum;

/**
 * 预约记录状态管理
 * @author zhj
 * @create 2024-04-17-16:26
 */
public class PreRegStateMachine {

    private PreRegStateEnum currentState;

    public PreRegStateMachine() {
        this.currentState = PreRegStateEnum.PRE_REG;
    }

    public PreRegStateEnum getCurrentState() {
        System.out.println("current state is : " + currentState);
        return currentState;
    }

    public void handleEvent(PreRegEventEnum event) throws Exception {
        switch (currentState) {
            case PRE_REG:
                if (event == PreRegEventEnum.REG) {
                    currentState = PreRegStateEnum.REG;
                } else if (event == PreRegEventEnum.PATIENT_CANCEL) {
                    currentState = PreRegStateEnum.PATIENT_CANCEL;
                } else if (event == PreRegEventEnum.HOSPITAL_CANCEL) {
                    currentState = PreRegStateEnum.HOSPITAL_CANCEL;
                } else {
                    throw new StateHandleException(currentState, event);
                }
                break;
            case REG:
                if (event == PreRegEventEnum.REG_CANCEL) {
                    currentState = PreRegStateEnum.REG_CANCEL;
                } else if (event == PreRegEventEnum.TREAT) {
                    currentState = PreRegStateEnum.TREAT;
                } else {
                    throw new StateHandleException(currentState, event);
                }
                break;
            default:
                throw new StateHandleException(currentState, event);
        }
    }
}
